/*
 * Copyright (c) 2019 Mike Penz
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mikepenz.iconics.sample.typeface;

import ohos.agp.text.Font;
import ohos.app.Context;
import ohos.utils.Pair;

import com.mikepenz.iconics.typeface.FontCreator;
import com.mikepenz.iconics.typeface.IIcon;
import com.mikepenz.iconics.typeface.ITypeface;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mikepenz on 01.11.14.
 *
 * @since 2014-01-11
 */
public class CustomFont implements ITypeface {
    private static final CustomFont INSTANCE = new CustomFont();

    private CustomFont() {
    }

    /**
     * 获取实例
     *
     * @return 实例对象
     */
    public static CustomFont getInstance() {
        return INSTANCE;
    }

    @Override
    public String getFontRes() {
        return "fontello.ttf";
    }

    @Override
    public Font getRawTypeface(Context context) {
        return FontCreator.createFont(context, getFontRes());
    }

    @Override
    public List<Pair<String, Character>> getCharacters() {
        List<Pair<String, Character>> pairs = new ArrayList<>();
        for (Icon icon : Icon.values()) {
            pairs.add(new Pair<>(icon.getName(), icon.getCharacter()));
        }
        return pairs;
    }

    @Override
    public String getMappingPrefix() {
        return "fon";
    }

    @Override
    public String getFontName() {
        return "CustomFont";
    }

    @Override
    public String getVersion() {
        return "1.0.0";
    }

    @Override
    public int getIconCount() {
        return getCharacters().size();
    }

    @Override
    public List<String> getIcons() {
        List<Pair<String, Character>> pairs = getCharacters();
        List<String> list = new ArrayList<>();
        for (Pair<String, Character> pair : pairs) {
            list.add(pair.f);
        }
        return list;
    }

    @Override
    public String getAuthor() {
        return "SampleCustomFont";
    }

    @Override
    public String getUrl() {
        return "";
    }

    @Override
    public String getDescription() {
        return "";
    }

    @Override
    public String getLicense() {
        return "";
    }

    @Override
    public String getLicenseUrl() {
        return "";
    }

    @Override
    public IIcon getIcon(String key) {
        return Icon.valueOf(key);
    }

    /**
     * 图标枚举
     *
     * @since 2021-06-16
     */
    public enum Icon implements IIcon {
        /**
         * 对应的图标
         */
        fon_test1('\ue800'),
        /**
         * 对应的图标
         */
        fon_test2('\ue801');

        private Character character;

        Icon(Character character) {
            this.character = character;
        }

        @Override
        public String getName() {
            return this.name();
        }

        @Override
        public String getFormattedName() {
            return "{" + getName() + "}";
        }

        @Override
        public Character getCharacter() {
            return this.character;
        }

        @Override
        public ITypeface getTypeface() {
            return CustomFont.getInstance();
        }
    }

}
